package com.annoncesautomobile.vue.rechercheAnnonce;

import java.util.ArrayList;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.Window;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.TextView;

import com.annoncesautomobile.R;
import com.annoncesautomobile.modele.util.IModelXML;
import com.annoncesautomobile.modele.util.ModelXML;
import com.annoncesautomobile.vue.SuperActivity;

public class ChoixPrixMinActivity extends SuperActivity {

	private ListView lv;
	private ArrayAdapter<String> adapter;
	private IModelXML modele;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);
		setContentView(R.layout.activity_choix_categorie);

		getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.custom_title_bar);
		TextView textViewActivityTitleText = (TextView) findViewById(R.id.activity_title_text);
		textViewActivityTitleText.setText(getString(R.string.title_activity_choix_prix_min));
		
		addBoutonBas();
		
		this.modele = ModelXML.getInstance();
		lv = (ListView) this.findViewById(R.id.listViewChoixItem);
		ArrayList<String> listPrixMin = (ArrayList<String>) this.modele.getListePrix();
		listPrixMin.add(0,"Tous prix");		
		adapter = new ArrayAdapter<String>(this, R.layout.list_item, R.id.product_name, listPrixMin);
		lv.setAdapter(adapter);
		
		lv.setOnItemClickListener(new OnItemClickListener() {

			@Override
			public void onItemClick(AdapterView<?> parent, View view, int position,
					long id) {

				String prixMin =  (String) parent.getItemAtPosition(position);
				if(prixMin.equals("Tous prix"))
				{
					prixMin = "-1";
				}
				System.out.println("Finish Prix : " + prixMin);
				Intent output = new Intent();
				output.putExtra("prix_min", prixMin);
				setResult(RESULT_OK, output);
				finish();
				
			}
		});
		
	}
	
	public void onBackPressed(View view) {
		this.onBackPressed();
	}
	
	@Override
	public void onBackPressed() {
		super.onBackPressed();
	}

}
